package main

import (
	"log"
	// ""

	"github.com/go-xorm/xorm"
	_ "github.com/mattn/go-sqlite3"
)

const (
	SQL_USER_TABLE = "" +
		"CREATE TABLE IF NOT EXISTS `user` (\n" +
		"  `user_id` INTEGER PRIMARY KEY  NOT NULL UNIQUE,\n" +
		"  `username` TEXT NOT NULL,\n" +
		"  `password` TEXT NOT NULL,\n" +
		"  `phone` TEXT NULL,\n" +
		"  `email` TEXT NULL,\n" +
		"  `create_time` INT  NOT NULL\n" +
		");"
)

type U2 struct {
	UserId     uint64
	Username   string
	Password   string
	Phone      string
	Email      string
	CreateTime int64
}

func (u2 *U2) TableName() string {
	return "user"

}

func main() {
	log.SetFlags(log.Lshortfile)
	engine, err := xorm.NewEngine("sqlite3", "a.db")
	if err != nil {
		log.Println(err)
		return
	}

	_, err = engine.Exec(SQL_USER_TABLE)
	if err != nil {
		log.Println(err)
		return
	}

	// a := &U2{
	// 	UserId:     1,
	// 	Username:   "yy",
	// 	Phone:      "11",
	// 	Email:      "email",
	// 	CreateTime: 111,
	// }

	// _, err = engine.Insert(a)
	// if err != nil {
	// 	log.Println(err)
	// 	return
	// }

	b := new(U2)
	has, err := engine.Where("user_id = ?", 1).Get(b)
	log.Println(has)
	log.Println(err)
	log.Println(b)
	u := &User{
		UserId:   b.UserId,
		Username: b.Username,
	}
	log.Println(u)

}
